package com.accp.vehiclecare.biz.xzhbiz;

import com.accp.vehiclecare.dao.xzhdao.FunctionDao;
import com.accp.vehiclecare.dao.xzhdao.JurisdictionDao;
import com.accp.vehiclecare.pojo.Jurisdiction;
import com.accp.vehiclecare.vo.xzhvo.FunctionVO;
import com.accp.vehiclecare.vo.xzhvo.JurisdictionVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("JurisdictionBiz")
public class JurisdictionBiz {
    @Autowired
    private JurisdictionDao jurisdictionDao;

    @Autowired
    private FunctionDao functionDao;

    /**
     * 查询父级权限下的子权限
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<JurisdictionVO> queryJurisdictionFunction(){
        return jurisdictionDao.queryJurisdictionFunction();
    }

    /**
     * 查询角色功能
     * @param jurisdictionid
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<FunctionVO> queryFunction(Integer jurisdictionid){
        return jurisdictionDao.queryFunction(jurisdictionid);
    }

    /**
     * 新增角色权限
     * @param jurisdictionid
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void addJurisdiction(Integer jurisdictionid,List<Integer> roleJurisdictions){
        try {
            //删除角色权限
            jurisdictionDao.removeJurisdiction(jurisdictionid);
            if(roleJurisdictions.size()!=0){
                //新增角色权限
                jurisdictionDao.addJurisdiction(jurisdictionid,roleJurisdictions);
            }
        }catch (Exception exception){
            throw new RuntimeException(exception);
        }
    }

   /* *//**
     * 新增角色权限
     * @param jurisdictionid
     * @param roleJurisdictions
     * @return
     *//*
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean addJurisdiction(Integer jurisdictionid,List<Integer> roleJurisdictions){
        int count =jurisdictionDao.addJurisdiction(jurisdictionid,roleJurisdictions);
        return count !=0;
    }*/

}
